home *** CD-ROM | disk | FTP | other *** search
/ Champak 26 (Anniversary Edition) / Volume 26 [Anniversary Edition] - JOGO DISK .iso / DEPOSITO / REmovido / Esportes / LightningBreak.swf / scripts / frame_1 / DoAction_9.as < prev    next >
Text File  |  2006-06-13  |  23KB  |  861 lines

  1. submitScore = function()
  2. {
  3.    game = "lightningbreak";
  4.    score = _root.totalScore;
  5.    if(_url.indexOf("playaholics") != -1)
  6.    {
  7.       getURL("http://www.playaholics.com/comp_entry.php","_top","POST");
  8.    }
  9.    else if(_url.indexOf("bluesqgames") != -1)
  10.    {
  11.       _root.submit.loadVariables("http://www.bluesqgames.net/multigame/submitscore/index.php?game_name=" + game + "&score=" + score,_root.submit);
  12.       getUrl("http://www.bluesqgames.net/multigame/playagain/index.php", "_top");
  13.    }
  14. };
  15. cleanup = function()
  16. {
  17.    Mouse.removeListener(this.stepAim);
  18.    Mouse.removeListener(this.stepPower);
  19.    this.onMouseDown = 0;
  20.    this.onMouseUp = 0;
  21.    this.onEnterFrame = 0;
  22.    this.timer.running = false;
  23.    _root.snd.stopAll();
  24.    _root.endGame();
  25. };
  26. endGame = function()
  27. {
  28.    if(_root.gameEnded)
  29.    {
  30.       return undefined;
  31.    }
  32.    _root.gameEnded = true;
  33.    if(_root.totalScore > 0)
  34.    {
  35.       _root.user.data.tr = int(_root.user.data.tr) + 1;
  36.       if(_root.user.data.tr == 0)
  37.       {
  38.          _root.user.data.tr = 1;
  39.       }
  40.       _root.user.data.th = Math.max(_root.totalScore,int(_root.user.data.th));
  41.       _root.user.data.ta = (Number(_root.user.data.ta) * (_root.user.data.tr - 1) + _root.totalScore) / _root.user.data.tr;
  42.       _root.flush();
  43.    }
  44. };
  45. this.timer = createEmptyMovieClip("timer",99);
  46. this.timer.running = false;
  47. this.timer.speed = 1;
  48. timer.init = function(timeTotal)
  49. {
  50.    this.timeTotal = timeTotal * 1000;
  51.    this.timeStart = getTimer();
  52.    _root.timeLeft = this.timeTotal;
  53.    this.running = false;
  54. };
  55. timer.onEnterFrame = function()
  56. {
  57.    if(_root.paused)
  58.    {
  59.       this.timestamp = getTimer();
  60.       return undefined;
  61.    }
  62.    _global.dt = (getTimer() - this.timestamp) / 33 * 0.3 + _global.dt * 0.7;
  63.    this.timestamp = getTimer();
  64.    if(this.running)
  65.    {
  66.       _root.timeLeft -= _global.dt * 33 * this.speed;
  67.    }
  68.    this.update();
  69. };
  70. timer.update = function()
  71. {
  72.    if(_root.paused)
  73.    {
  74.       return undefined;
  75.    }
  76.    _root.bg.time.time.time.gotoAndStop(Math.max(Math.floor(_root.timeLeft / 1000) + 2,1));
  77.    if(_root.timeLeft <= -0.5 && this.running)
  78.    {
  79.       this.running = false;
  80.       if(_root.onEnterFrame != stepRoll)
  81.       {
  82.          _root.startLevelOver();
  83.       }
  84.    }
  85. };
  86. timer.initColorSwap = function()
  87. {
  88.    this.colorSwapTimer = 0;
  89.    var i = 1;
  90.    while(i < _root.ballsAmount)
  91.    {
  92.       _root.balls[i].initColorSwap();
  93.       i++;
  94.    }
  95. };
  96. timer.stepColorSwap = function()
  97. {
  98.    if(_root.paused)
  99.    {
  100.       return undefined;
  101.    }
  102.    if(!_root.lvl.colorSwap)
  103.    {
  104.       return undefined;
  105.    }
  106.    this.colorSwapTimer += _global.dt;
  107.    if(this.colorSwapTimer > _root.swapTimerThreashold)
  108.    {
  109.       this.colorSwapTimer = 0;
  110.       _root.colorSwap();
  111.    }
  112. };
  113. timer.timestamp = getTimer();
  114. initGame = function()
  115. {
  116.    _root.levelsPlayed = 0;
  117.    _root.totalShots = 0;
  118.    _root.gameEnded = false;
  119.    _root.actScore = 0;
  120.    _root.totalScore = 0;
  121.    _root.actBreak = 0;
  122.    _root.timeLeft = -1;
  123.    _root.pointer.gotoAndStop("wait");
  124.    _root.timer.running = false;
  125.    initTable();
  126.    loadLevel(_root.actLvl);
  127. };
  128. initTable = function()
  129. {
  130.    this.balls = new Array();
  131.    var i = 0;
  132.    while(i < this.ballsAmount + 1)
  133.    {
  134.       this.balls[i] = new CBall(i,this["b" + i]);
  135.       i++;
  136.    }
  137.    this.lids = new Array();
  138.    var i = 0;
  139.    while(i < 6)
  140.    {
  141.       this.lids[i] = _root["l" + i];
  142.       i++;
  143.    }
  144. };
  145. loadLevel = function(id)
  146. {
  147.    _root.actLvl = id;
  148.    _root.actLevel = _root.actLvl + 1;
  149.    if(_root.actLvl > _root.maxLevel)
  150.    {
  151.       _root.user.data.maxLevel = _root.actLvl;
  152.       _root.flush();
  153.       _root.maxLevel = int(_root.user.data.maxLevel);
  154.    }
  155.    _root.actScore = 0;
  156.    _root.actBreak = 0;
  157.    _root.actPottedRed = 0;
  158.    _root.actPottedColor = 0;
  159.    _root.actPottedOrder = "";
  160.    _root.nominatedNext = 1;
  161.    _root.actRoundsPlayed = _root.stats[this.actLvl].rounds;
  162.    _root.actHighScore = _root.stats[this.actLvl].highscore;
  163.    _root.actAvgScore = _root.stats[this.actLvl].average;
  164.    _root.lvl = _root.lvls[_root.actLvl % 20];
  165.    _root.lvl.init();
  166.    _root.timePerLevel = this.lvl.time * (1 - Math.floor(_root.actLvl / 20) * 0.1) + 0.99;
  167.    if(_root.timePerLevel == 100.99)
  168.    {
  169.       _root.timePerLevel = 99.99;
  170.    }
  171.    _root.bg.outer.gotoAndStop(_root.lvl.skin);
  172.    _root.bg.time.inner.gotoAndStop(_root.lvl.skin);
  173.    if(_root.lvl.breakout)
  174.    {
  175.       _root.balls[8].setPos(100,100);
  176.       _root.balls[8].reset();
  177.    }
  178.    _root.h0._visible = _root.lvl.frame != 1;
  179.    _root.h1._visible = _root.lvl.frame != 1;
  180.    _root.h2._visible = _root.lvl.frame != 1;
  181.    _root.h3._visible = _root.lvl.frame != 2;
  182.    _root.h4._visible = _root.lvl.frame != 2;
  183.    _root.h5._visible = _root.lvl.frame != 2;
  184.    _root.frame.gotoAndStop(_root.lvl.frame + 1);
  185.    _root.table = _root.tables[_root.lvl.frame];
  186.    _root.startLevel();
  187. };
  188. startLevel = function()
  189. {
  190.    this.phase = 0;
  191.    this.onEnterFrame = this.stepLevel;
  192.    this.nominated = 1;
  193.    _root.timer.initColorSwap();
  194. };
  195. stepLevel = function()
  196. {
  197.    if(this.paused)
  198.    {
  199.       return undefined;
  200.    }
  201.    this.timer.stepColorSwap();
  202.    if(this.phaseDelay > 0)
  203.    {
  204.       this.phaseDelay -= _global.dt;
  205.       return undefined;
  206.    }
  207.    switch(this.phase)
  208.    {
  209.       case 0:
  210.          _root.snd.play("levelmusic");
  211.          _root.bg.gotoAndPlay("level");
  212.          this.phase = this.phase + 1;
  213.          break;
  214.       case 1:
  215.          break;
  216.       case 2:
  217.          _root.osd.gotoAndPlay("level");
  218.          this.phase = this.phase + 1;
  219.          break;
  220.       case 3:
  221.          break;
  222.       case 4:
  223.          _root.osd.gotoAndPlay("countdown3");
  224.          _root.snd.playEvent("tic",50);
  225.          this.phaseDelay = 20;
  226.          this.phase = this.phase + 1;
  227.          break;
  228.       case 5:
  229.          _root.osd.gotoAndPlay("countdown2");
  230.          _root.snd.playEvent("tic",50);
  231.          this.phaseDelay = 20;
  232.          this.phase = this.phase + 1;
  233.          break;
  234.       case 6:
  235.          _root.osd.gotoAndPlay("countdown1");
  236.          _root.snd.playEvent("tic",50);
  237.          this.phaseDelay = 20;
  238.          this.phase = this.phase + 1;
  239.          break;
  240.       case 7:
  241.          _root.osd.gotoAndPlay("go");
  242.          _root.snd.play("go");
  243.          this.phaseDelay = 20;
  244.          this.phase = this.phase + 1;
  245.       case 8:
  246.          if(this.totalShots > 0 || this.actLvl != 0)
  247.          {
  248.             _root.spotBall(0);
  249.             _root.spotBall(1,1);
  250.          }
  251.          var i = 0;
  252.          while(i < _root.ballsAmount + _root.lvl.breakout)
  253.          {
  254.             _root.balls[i].mc.gotoAndPlay("appear");
  255.             i++;
  256.          }
  257.          this.phaseDelay = 10;
  258.          this.phase = this.phase + 1;
  259.          break;
  260.       case 9:
  261.          _root.timer.running = true;
  262.          startAim();
  263.    }
  264. };
  265. startAim = function()
  266. {
  267.    this.nominated = this.nominatedNext;
  268.    this.validPotMode = 0;
  269.    this.shotPots = "";
  270.    _root.pointer.gotoAndStop("aim");
  271.    var i = 0;
  272.    while(i < _root.ballsAmount)
  273.    {
  274.       if(_root.balls[i].spot || int(_root.balls[i].x) == 0 || int(_root.balls[i].y) == 0)
  275.       {
  276.          _root.spotBall(i);
  277.       }
  278.       i++;
  279.    }
  280.    _root.cue._visible = true;
  281.    _root.cue.scale._visible = false;
  282.    _root.cue.gfx._y = this.balls[0].radius * -1 - this.aimDistance;
  283.    _root.cue._x = this.balls[0].x;
  284.    _root.cue._y = this.balls[0].y;
  285.    if(_root.lvl.needOrder eq "")
  286.    {
  287.       if(this.nominated > 0)
  288.       {
  289.          this.balls[this.nominated].mc.marker.gotoAndPlay("active");
  290.       }
  291.       else
  292.       {
  293.          var i = 2;
  294.          while(i < _root.ballsAmount)
  295.          {
  296.             this.balls[i].mc.marker.gotoAndPlay("active");
  297.             i++;
  298.          }
  299.       }
  300.    }
  301.    else
  302.    {
  303.       var target = _root.lvl.needOrder.charAt(_root.actPottedOrder.length);
  304.       this.balls[target].mc.marker.gotoAndPlay("active");
  305.       this.nominated = target;
  306.    }
  307.    var i = 0;
  308.    while(i < this.ballsAmount)
  309.    {
  310.       this.balls[i].showLabel();
  311.       i++;
  312.    }
  313.    Mouse.addListener(this.stepAim);
  314.    this.onEnterFrame = this.stepAim;
  315. };
  316. stepAim = function()
  317. {
  318.    if(_root.paused)
  319.    {
  320.       return undefined;
  321.    }
  322.    this.timer.stepColorSwap();
  323.    if(this.phaseDelay > 0)
  324.    {
  325.       this.phaseDelay -= _global.dt;
  326.       return undefined;
  327.    }
  328.    if(_root._ymouse > 348)
  329.    {
  330.       _root.pointer.gotoAndStop("wait");
  331.    }
  332.    else
  333.    {
  334.       _root.pointer.gotoAndStop("aim");
  335.    }
  336.    _root.cue._alpha = Math.min(_root.cue._alpha + 15,100);
  337.    _root.cue._rotation = _global.v2d.math.r2vertSgnAngle(this.balls[0].x,this.balls[0].y,_root._xmouse,_root._ymouse) / 3.141592653589793 * 180 - 180;
  338.    _root.aimVector = _global.v2d.math.unify({x:_root._xmouse - _root.balls[0].x,y:_root._ymouse - _root.balls[0].y});
  339. };
  340. stepAim.onMouseDown = function()
  341. {
  342.    if(_root.paused)
  343.    {
  344.       return undefined;
  345.    }
  346.    if(_root._ymouse > 348)
  347.    {
  348.       return undefined;
  349.    }
  350.    Mouse.removeListener(this);
  351.    _root.startPower();
  352. };
  353. startPower = function()
  354. {
  355.    Mouse.addListener(this.stepPower);
  356.    _root.cue._alpha = 100;
  357.    _root.cue.scale._visible = true;
  358.    _root.cue.scale._y = this.balls[0].radius * -1 - this.aimDistance;
  359.    this.startPowerTime = getTimer();
  360.    this.powerOld = 0;
  361.    this.powerAct = 0;
  362.    this.powerV = 0;
  363.    this.onEnterFrame = this.stepPower;
  364. };
  365. stepPower = function()
  366. {
  367.    if(_root.paused)
  368.    {
  369.       return undefined;
  370.    }
  371.    this.stepAim();
  372.    var dt = getTimer() - this.startPowerTime;
  373.    this.powerAct = (1 - Math.cos(dt / 350)) / 2;
  374.    this.cueV = (this.powerAct - this.powerOld) * this.aimRange * -1 / _global.dt;
  375.    this.cue.scale.gotoAndStop(1 + Math.floor(this.powerAct * 50));
  376.    this.pointer.gotoAndStop(2 + Math.floor(this.powerAct * 50));
  377.    this.powerOld = this.powerAct;
  378.    _root.cue.gfx._y = this.balls[0].radius * -1 - this.aimDistance - this.powerAct * this.aimRange;
  379. };
  380. stepPower.onMouseUp = function()
  381. {
  382.    Mouse.removeListener(this);
  383.    _root.pointer.gotoAndStop(1);
  384.    _root.cue.scale._visible = false;
  385.    _root.cueA = Math.max(Math.pow(_root.powerAct * 4,1.8),0.1);
  386.    _root.startShoot();
  387. };
  388. startShoot = function()
  389. {
  390.    this.totalShots = this.totalShots + 1;
  391.    this.onEnterFrame = this.stepShoot;
  392.    var i = 0;
  393.    while(i < this.ballsAmount)
  394.    {
  395.       this.balls[i].hideLabel();
  396.       i++;
  397.    }
  398. };
  399. stepShoot = function()
  400. {
  401.    if(_root.paused)
  402.    {
  403.       return undefined;
  404.    }
  405.    this.timer.stepColorSwap();
  406.    ty = _root.cue.gfx._y + this.cueV * _global.dt;
  407.    this.cueV += this.cueA * _global.dt;
  408.    if(ty > this.balls[0].radius * -1)
  409.    {
  410.       ty = this.balls[0].radius * -1;
  411.       _root.snd.playEvent("cuehit",_root.powerAct);
  412.       this.cueV *= _root.lvl.speedUp;
  413.       this.balls[0].vx = this.aimVector.x * this.cueV;
  414.       this.balls[0].vy = this.aimVector.y * this.cueV;
  415.       this.startRoll();
  416.    }
  417.    _root.cue.gfx._y = ty;
  418. };
  419. startRoll = function()
  420. {
  421.    var i = 1;
  422.    while(i < _root.ballsAmount)
  423.    {
  424.       if(this.balls[i].mc.marker._currentframe > 1)
  425.       {
  426.          this.balls[i].mc.marker.gotoAndPlay("vanish");
  427.       }
  428.       i++;
  429.    }
  430.    this.replaySave();
  431.    _root.pointer.gotoAndStop("wait");
  432.    this.firstHit = 0;
  433.    this.stepRollCount = 0;
  434.    this.onEnterFrame = this.stepRoll;
  435. };
  436. stepRoll = function()
  437. {
  438.    if(_root.paused)
  439.    {
  440.       return undefined;
  441.    }
  442.    this.timer.stepColorSwap();
  443.    if(this.steps == 0)
  444.    {
  445.       return undefined;
  446.    }
  447.    if(this.steps > 0)
  448.    {
  449.       this.steps--;
  450.    }
  451.    _root.gstep.clear();
  452.    this.stepRollTotalMovement = 0;
  453.    var i = 0;
  454.    while(i < this.ballsAmount + _root.lvl.breakout)
  455.    {
  456.       this.balls[i].move();
  457.       i++;
  458.    }
  459.    this.stepRollCount += _global.dt;
  460.    if(this.stepRollCount > 30)
  461.    {
  462.       if(_root.cue._alpha > 0)
  463.       {
  464.          _root.cue._alpha = Math.max(_root.cue._alpha * 0.8 - 1,0);
  465.       }
  466.       else
  467.       {
  468.          _root.cue._visible = false;
  469.       }
  470.       if(this.stepRollTotalMovement < 0.2)
  471.       {
  472.          var i = 0;
  473.          while(i < this.ballsAmount)
  474.          {
  475.             this.balls[i].setSpeed(0,0);
  476.             i++;
  477.          }
  478.          _root.pointer.gotoAndStop("ready");
  479.          if(_root.missionAccomplished())
  480.          {
  481.             this.startLevelOver();
  482.             return undefined;
  483.          }
  484.          var allPotted = true;
  485.          var i = 1;
  486.          while(i < _root.ballsAmount)
  487.          {
  488.             if(_root.balls[i].potted == -1)
  489.             {
  490.                allPotted = false;
  491.             }
  492.             i++;
  493.          }
  494.          if(allPotted)
  495.          {
  496.             this.startLevelOver();
  497.             return undefined;
  498.          }
  499.          if(_root.firstHit == 0 && _root.balls[0].potted == -1)
  500.          {
  501.             _root.foul(4,"- 4 seconds for missing");
  502.          }
  503.          if(_root.lvl.needExact != 0 && _root.lvl.actBreak > _root.lvl.needExact)
  504.          {
  505.             this.startLevelOver();
  506.             return undefined;
  507.          }
  508.          if(this.timeLeft <= 0)
  509.          {
  510.             this.startLevelOver();
  511.          }
  512.          else
  513.          {
  514.             this.startAim();
  515.          }
  516.       }
  517.    }
  518. };
  519. startLevelOver = function(gameover)
  520. {
  521.    this.phase = 0;
  522.    if(gameover)
  523.    {
  524.       this.phase = "alreadydead";
  525.    }
  526.    this.phaseDelay = 0;
  527.    Mouse.removeListener(this.stepPower);
  528.    Mouse.removeListener(this.stepAim);
  529.    this.pointer.gotoAndStop("wait");
  530.    this.onEnterFrame = this.stepLevelOver;
  531.    _root.stats[this.actLvl].rounds = _root.stats[this.actLvl].rounds + 1;
  532.    _root.stats[this.actLvl].highscore = Math.max(_root.stats[this.actLvl].highscore,_root.actScore);
  533.    _root.stats[this.actLvl].average = Math.round((_root.stats[this.actLvl].average * (_root.stats[this.actLvl].rounds - 1) + _root.actScore) / _root.stats[this.actLvl].rounds);
  534.    _root.user.data[this.actLvl + "r"] = _root.stats[this.actLvl].rounds;
  535.    _root.user.data[this.actLvl + "h"] = _root.stats[this.actLvl].highscore;
  536.    _root.user.data[this.actLvl + "a"] = _root.stats[this.actLvl].average;
  537.    _root.flush();
  538. };
  539. stepLevelOver = function()
  540. {
  541.    if(_root.paused)
  542.    {
  543.       return undefined;
  544.    }
  545.    if(_root.cue._alpha > 0)
  546.    {
  547.       _root.cue._alpha = Math.max(_root.cue._alpha * 0.9 - 1,0);
  548.    }
  549.    else
  550.    {
  551.       _root.cue._visible = false;
  552.    }
  553.    if(this.phaseDelay > 0)
  554.    {
  555.       this.phaseDelay -= _global.dt;
  556.       return undefined;
  557.    }
  558.    switch(this.phase)
  559.    {
  560.       case 0:
  561.          this.snd.play("thunderRumble");
  562.          if(_root.missionAccomplished())
  563.          {
  564.             _root.levelsPlayed = _root.levelsPlayed + 1;
  565.             _root.actTimeBonus = _root.levelsPlayed * Math.floor(_root.timeLeft / 1000);
  566.             _root.totalScore += _root.actTimeBonus;
  567.             _root.actScore += _root.actTimeBonus;
  568.             _root.osd.gotoAndPlay("welldone");
  569.          }
  570.          else
  571.          {
  572.             _root.osd.gotoAndPlay("timeout");
  573.          }
  574.          this.phaseDelay = 30;
  575.          this.phase = this.phase + 1;
  576.          break;
  577.       case 1:
  578.          if(_root.missionAccomplished())
  579.          {
  580.             _root.tube.empty();
  581.          }
  582.          this.phaseDelay = 30;
  583.          this.phase = this.phase + 1;
  584.          break;
  585.       case 2:
  586.          if(_root.missionAccomplished())
  587.          {
  588.             var i = 0;
  589.             while(i < _root.ballsAmount)
  590.             {
  591.                _root.balls[i].mc.gotoAndPlay("vanish");
  592.                i++;
  593.             }
  594.          }
  595.          this.phaseDelay = 30;
  596.          this.phase = this.phase + 1;
  597.          break;
  598.       case 3:
  599.          this.phase = this.phase + 1;
  600.          if(_root.missionAccomplished())
  601.          {
  602.             this.loadLevel(_root.actLvl + 1);
  603.          }
  604.          break;
  605.       case 4:
  606.          this.snd.play("gameover");
  607.          _root.osd.gotoAndPlay("gameover");
  608.          this.phase = this.phase + 1;
  609.          break;
  610.       case "alreadydead":
  611.          this.phase = 5;
  612.       case 5:
  613.    }
  614. };
  615. replaySave = function(slot)
  616. {
  617.    if(slot)
  618.    {
  619.       this.replayDataSlots[slot] = this.replayData;
  620.       var i = 0;
  621.       while(i < this.ballsAmount)
  622.       {
  623.          i++;
  624.       }
  625.       return undefined;
  626.    }
  627.    this.replayData = new Array();
  628.    var i = 0;
  629.    while(i < this.ballsAmount)
  630.    {
  631.       this.replayData[i] = {x:this.balls[i].x,y:this.balls[i].y,vx:this.balls[i].vx,vy:this.balls[i].vy};
  632.       i++;
  633.    }
  634. };
  635. replayLoad = function(slot)
  636. {
  637.    if(slot)
  638.    {
  639.       this.replayData = this.replayDataSlots[slot];
  640.    }
  641.    if(!this.replayData)
  642.    {
  643.       return undefined;
  644.    }
  645.    var i = 0;
  646.    while(i < this.ballsAmount)
  647.    {
  648.       this.balls[i].setPos(this.replayData[i].x,this.replayData[i].y);
  649.       this.balls[i].setSpeed(this.replayData[i].vx,this.replayData[i].vy);
  650.       i++;
  651.    }
  652.    this.cue._visible = false;
  653.    this.cue._alpha = 0;
  654.    this.startRoll();
  655. };
  656. standardShot = function()
  657. {
  658.    this.balls[0].vx = 20;
  659.    this.balls[0].vy = 0;
  660.    this.startRoll();
  661. };
  662. pot = function(value, id)
  663. {
  664.    this.snd.play("pot");
  665.    _root.balls[id].spot = 1;
  666.    if(value !== 0)
  667.    {
  668.       this.shotPots += "" + value;
  669.       if(_root.lvl.needOrder.substr(this.actPottedOrder.length,1) eq value || (this.nominated == value || this.nominated == 0 && value > 1) || this.validPotMode)
  670.       {
  671.          if(_root.lvl.dontRespotColors && value > 1)
  672.          {
  673.             _root.balls[id].spot = 0;
  674.          }
  675.          if(this.validPotMode)
  676.          {
  677.             _root.osd.gotoAndPlay("excellent");
  678.             _root.snd.play("excellent");
  679.          }
  680.          this.validPotMode = 1;
  681.          this.score(value);
  682.          if(value == 1)
  683.          {
  684.             this.nominatedNext = 0;
  685.             this.actPottedRed = this.actPottedRed + 1;
  686.          }
  687.          else
  688.          {
  689.             this.nominatedNext = 1;
  690.             this.actPottedColor = this.actPottedColor + 1;
  691.          }
  692.          this.actPottedOrder += value;
  693.          _root.tube.addBall(value);
  694.       }
  695.       else
  696.       {
  697.          _root.foul(4,"- 4 seconds for potting wrong ball");
  698.       }
  699.    }
  700.    else
  701.    {
  702.       _root.foul(4,"- 4 seconds for potting white ball");
  703.    }
  704. };
  705. score = function(value)
  706. {
  707.    _root.actBreak += value;
  708.    _root.actScore += value * Math.floor(_root.timeLeft / 1000);
  709.    _root.totalScore += value * Math.floor(_root.timeLeft / 1000);
  710. };
  711. collision = function(b0, b1)
  712. {
  713.    if(b0.id == 0 || b1.id == 0)
  714.    {
  715.       var col = b0.id + b1.id;
  716.       this.firstHit = col;
  717.       this.firstHitLegal = 1;
  718.    }
  719. };
  720. foul = function(seconds, text)
  721. {
  722.    _root.lightning.gotoAndPlay("double");
  723.    _root.actFoul = text;
  724.    _root.timeLeft -= seconds * 1000;
  725.    _root.osd.gotoAndPlay("foul");
  726.    _root.snd.play("foul");
  727. };
  728. spotBall = function(id, flags)
  729. {
  730.    var tableCenterX = _root.table.x0 + (_root.table.x1 - _root.table.x0) / 2;
  731.    var tableCenterY = _root.table.y0 + (_root.table.y1 - _root.table.y0) / 2;
  732.    var difficulty = 0.5;
  733.    var posX;
  734.    var posY;
  735.    putX = _root.lvlProto[id].x;
  736.    putY = _root.lvlProto[id].y;
  737.    while(true)
  738.    {
  739.       if(id == 0)
  740.       {
  741.          putX = _root.lvlProto[id].x;
  742.          putY = tableCenterY + (_root.table.y1 - _root.table.y0 - _root.ballSize - 2) * (Math.random() - 0.5);
  743.       }
  744.       else if(id == 1)
  745.       {
  746.          r0 = Math.random();
  747.          r1 = Math.random() - 0.5;
  748.          if(flags && 1)
  749.          {
  750.             r0 = Math.max(r0,0.2);
  751.             r1 = Math.max(0.3,Math.abs(r1));
  752.             if(_root.balls[0].y < tableCenterY)
  753.             {
  754.                r1 *= -1;
  755.             }
  756.          }
  757.          putX = _root.lvlProto[id].x + 85 * r0;
  758.          putY = _root.lvlProto[id].y + 150 * r1 * r0;
  759.       }
  760.       var space = 999;
  761.       var i = 0;
  762.       while(i < _root.ballsAmount)
  763.       {
  764.          if(!(i == id || _root.balls[i].potted > -1))
  765.          {
  766.             space = Math.min(space,_global.v2d.math.p2pDistance(putX,putY,_root.balls[i].x,_root.balls[i].y));
  767.          }
  768.          i++;
  769.       }
  770.       if(space > _root.ballSize + 1)
  771.       {
  772.          _root.balls[id].reset();
  773.          _root.balls[id].setPos(putX,putY);
  774.          _root.balls[id].mc.gotoAndPlay("appear");
  775.          _root.balls[id].spot = 0;
  776.          break;
  777.       }
  778.       putX += _root.ballSize + 2;
  779.       if(putX > _root.table.x1 - _root.ballSize)
  780.       {
  781.          putX = _root.lvlProto[id].x;
  782.          putY += _root.ballSize + 2;
  783.       }
  784.    }
  785. };
  786. missionAccomplished = function()
  787. {
  788.    if(_root.actPottedRed >= _root.lvl.needPottedRed && _root.actPottedColor >= _root.lvl.needPottedColor && _root.actBreak >= _root.lvl.needBreak && (_root.actBreak == _root.lvl.needExact || _root.lvl.needExact == 0) && (_root.actPottedOrder == _root.lvl.needOrder || _root.lvl.needOrder eq ""))
  789.    {
  790.       this.timer.running = false;
  791.       return true;
  792.    }
  793.    return false;
  794. };
  795. colorSwap = function()
  796. {
  797.    if(!_root.lvl.colorSwap)
  798.    {
  799.       return undefined;
  800.    }
  801.    switch(_root.lvl.colorSwap)
  802.    {
  803.       case 1:
  804.          var i = 1;
  805.          while(i < _root.ballsAmount)
  806.          {
  807.             _root.balls[i].colorSwap();
  808.             i++;
  809.          }
  810.          break;
  811.       case 2:
  812.          var old = - 1;
  813.          var i = 0;
  814.          while(i < _root.ballsAmount)
  815.          {
  816.             if(_root.balls[i].glass)
  817.             {
  818.                old = i;
  819.                _root.balls[i].setGlass(0);
  820.             }
  821.             i++;
  822.          }
  823.          var closeId;
  824.          while(true)
  825.          {
  826.             closeId = random(_root.ballsAmount - 1) + 1;
  827.             if(closeId != old)
  828.             {
  829.                break;
  830.             }
  831.          }
  832.          _root.balls[closeId].setGlass(1);
  833.          break;
  834.       case 3:
  835.          var old = - 1;
  836.          var i = 0;
  837.          while(i < 6)
  838.          {
  839.             if(_root["l" + i].closed)
  840.             {
  841.                _root["l" + i].hand.gotoAndPlay("open");
  842.             }
  843.             else
  844.             {
  845.                old = i;
  846.             }
  847.             i++;
  848.          }
  849.          var closeId;
  850.          while(true)
  851.          {
  852.             closeId = random(6);
  853.             if(closeId != old)
  854.             {
  855.                break;
  856.             }
  857.          }
  858.          _root["l" + closeId].hand.gotoAndPlay("close");
  859.    }
  860. };
  861.